<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>auto cheyun cms</title>

    <link href="<?php echo base_url(); ?>static/css/bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>static/font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>static/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>static/css/animate.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>static/css/style.css" rel="stylesheet">

    <link href="<?php echo base_url(); ?>static/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">

    <!-- 导入jquery -->
    <script src="<?php echo base_url(); ?>static/js/jquery-2.1.1.js"></script>

</head>

<body>
	
	<div id="wrapper">
		<!-- 左侧菜单 -->
		<?php $this->load->view('admin/common/left.html'); ?>
		<div id="page-wrapper" class="gray-bg">
			<!-- 公共头部 -->
			<?php $this->load->view('admin/common/header.html'); ?>
			<!-- content 主区域 -->
			<div class="wrapper wrapper-content">
            <form method="post" class="form-horizontal" id="platform">
	            <div class="row">
	                <div class="col-lg-12">
		                <div class="ibox float-e-margins">
                            <?php foreach ($nodes as $k => $v): ?>
                            <dl>
                            <div class="ibox-title">
                                <h5>
                                    <input level="1" type="checkbox" class="i-checks" <?php echo $v['access']?"checked='checked'":'' ?> name="rules[]" value="<?php echo $v['id'] ?>">&nbsp;<?php echo $v['title'] ?> 
                                </h5>
                            </div>
                            <?php if ($v['child']): ?>
                            <div class="ibox-content">
                                <div class="form-group">
                                    <div class="col-sm-10">
                                    <?php foreach ($v['child'] as $val): ?>
                                    <label class="checkbox-inline i-checks">
                                        <input level="2" type="checkbox" <?php echo $val['access']?"checked='checked'":'' ?> name="rules[]" value="<?php echo $val['id'] ?>">&nbsp;<?php echo $val['title'] ?>
                                    </label>
                                    <?php endforeach ?>
                                    </div>
                                </div>
                            </div>
                                
                            <?php endif ?>
                            </dl>
                            <?php endforeach ?>


		                </div>
		            </div>
	            </div>
                <!-- 提交按钮 -->
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-2">
                        <button class="btn btn-primary" type="submit">保存</button>
                    </div>
                </div>
            </form>

			</div>

        <?php $this->load->view('admin/common/footer.html'); ?>

		</div>
	</div>


    <!-- Mainly scripts -->
    <script src="<?php echo base_url(); ?>static/js/jquery-2.1.1.js"></script>
    <script src="<?php echo base_url(); ?>static/js/bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>static/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="<?php echo base_url(); ?>static/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>

    <!-- Custom and plugin javascript -->
    <script src="<?php echo base_url(); ?>static/js/inspinia.js"></script>
    <script src="<?php echo base_url(); ?>static/js/plugins/pace/pace.min.js"></script>

    <!-- iCheck -->
    <script src="<?php echo base_url(); ?>static/js/plugins/iCheck/icheck.min.js"></script>
    <script>
        $(document).ready(function () {
           

            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });

             $('input[level=1]').on('ifChanged', function(event){ //ifCreated 事件应该在插件初始化之前绑定 
                inputs = $(this).parents('dl').find('.ibox-content').find('input');
                parent_input = $(this);
                
                inputs.each(function(){
                    // console.log($(this));
                    parent_input.is(':checked') ? $(this).iCheck('check') : $(this).iCheck('uncheck');
                });
            });

            $('input[level=2]').on('ifChanged', function(event) {
                inputs = $(this).parent().parents('dl').find('.ibox-content').find('input:checked');
                parent_input = $(this).parents('.ibox-content').prev().find('input');
                // console.log(inputs.length);

                if (inputs.length >= 1) {
                    parent_input.iCheck('check');
                } else {
                    parent_input.iCheck('uncheck');
                }

            });
        });
    </script>

</body>